package com.hwsc.pay.utils;

import cn.hutool.crypto.symmetric.AES;
import com.hwsc.pay.constant.Constants;

import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.net.URLEncoder;
import java.util.Base64;

public class AESUtil {
    private static final String AES = "AES";

    private static final String  key="N4BN635YI5XS7S56";
    private static final String  Iv="DYgjCEIMVrj2W9xN";




    // 解密
    public static String decrypt(String content) throws Exception {
        cn.hutool.crypto.symmetric.AES aes = new AES("CBC", "PKCS7Padding",
                // 密钥，可以自定义
                key.getBytes(),
                Iv.getBytes());
        return aes.encryptHex(content);
    }

    public static void main(String[] args) throws Exception {
        String url = "https://dqvvs89v0z74.guyubao.com/pay/scan?";
        String params = "merchantNo=95162094121P2FM";


        String encodedData = URLEncoder.encode(decrypt(params), "UTF-8");
        System.out.println("编码后的数据: " + encodedData);

        String encryptedUrl = url + "sign=" + encodedData;
        System.out.println("加密后的URL: " + encryptedUrl);
    }
}